package net.sf.rose.business.bean.database;

import java.io.Serializable;

import net.sf.rose.util.DataUtil;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

/**
 * @author fengjian
 * @since 2014-6-11
 */
@Root(name = "field")
public class FieldMetaBean implements Serializable {

	private static final long serialVersionUID = 1L;

	/** 字段名称 */
	@Attribute
	private String name = null;

	/** 字段说明 */
	@Attribute(required = false)
	private String text = null;

	/** 数据类型 */
	@Attribute
	private String type = null;

	/** 长度 */
	@Attribute(required = false)
	private String size = null;

	/** 主键 */
	@Attribute(required = false)
	private boolean pk = false;

	/** 可否为NULL */
	@Attribute(required = false)
	private boolean canNull = false;

	/** 默认值 */
	@Attribute(required = false)
	private String defaultValue = null;

	/** 连接 */
	@Element(required = false)
	private LinkMetaBean link = null;

	public boolean equals(FieldMetaBean bean) {
		if (!this.name.equals(bean.name))
			return false;
		if (!this.type.equals(bean.type))
			return false;
		if (!DataUtil.equals(this.size, bean.size))
			return false;
		if (!this.pk == bean.pk)
			return false;
		if (!this.canNull == bean.canNull)
			return false;
		if (!DataUtil.equals(this.defaultValue, bean.defaultValue))
			return false;
		return true;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public boolean isPk() {
		return pk;
	}

	public void setPk(boolean pk) {
		this.pk = pk;
	}

	public boolean isCanNull() {
		return canNull;
	}

	public void setCanNull(boolean canNull) {
		this.canNull = canNull;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public LinkMetaBean getLink() {
		return link;
	}

	public void setLink(LinkMetaBean link) {
		this.link = link;
	}

	public void update(FieldMetaBean bean) {
		this.canNull = bean.canNull;
		this.defaultValue = bean.defaultValue;
		this.link = bean.link;
		this.name = bean.name;
		this.pk = bean.pk;
		this.size = bean.size;
		this.text = bean.text;
		this.type = bean.type;
	}
}
